<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/17
 * Time: 15:57
 */

if(empty($_POST["aname"])){
    die("用户名不能为空");
}
if(empty($_POST["apassword"])){
    die("密码不能为空");
}
if(empty($_POST["ackpassword"])){
    die("确认密码不能为空");
}
$id = $_POST["id"];
$name = $_POST["aname"];
$password=$_POST["apassword"];
$ackpassword=$_POST["ackpassword"];

if($password!=$ackpassword)
{
    echo "<script> {window.alert('两次密码不一致');location.href='aList.php'} </script>";

    exit;
}
else {

    $sql = "update admin set adminName='$name',passWord='$password'";
    $sql .= "where id=$id";
// 3. 执行数据库操作，将update语句发送至数据库
//echo $sql;
// 引入打开数据库的代码
    include_once dirname(__FILE__) . '../../common/conn.php';

    $res = mysqli_query($con, $sql);

    mysqli_close($con);
// 4. 判断执行结果，返回提示信息
    if ($res) {
        echo "<script> {window.alert('保存成功');location.href='aList.php'} </script>";

        exit;
    } else {
        echo "<script> {window.alert('保存失败，请返回查看');location.href='aList.php'} </script>";

        exit;
    }
}